//
//  TextFieldViewController.swift
//  UI
//
//  Created by admin on 14/9/22.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//

import UIKit
//UITextField和UITextView类都遵循UITextInputTraits协议，该协议定义了一些配置键盘的属性[性状]
class TextFieldViewController: UIViewController, UITextFieldDelegate, UITextInputTraits {
    @IBOutlet weak var tf: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        tf.delegate = self
        tf.returnKeyType = UIReturnKeyType.Done
        tf.secureTextEntry = true
        tf.enablesReturnKeyAutomatically = false
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    //MARK: - UITextFieldDelegate
    func textFieldShouldBeginEditing(textField: UITextField!) -> Bool {
        return true
    }// return NO to disallow editing.
    func textFieldShouldEndEditing(textField: UITextField!) -> Bool {
        return true
    }// return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end
    
    
    func textFieldDidBeginEditing(textField: UITextField!){
        
    } // became first responder
    func textFieldDidEndEditing(textField: UITextField!){
        
    } // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called
    
    
    
    func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool {
        return true
    }// return NO to not change text
    
    func textFieldShouldClear(textField: UITextField!) -> Bool {
        return true
    }// called when clear button pressed. return NO to ignore (no notifications)
    
    
    
    //当用户点击return键时，键盘放弃首要响应状态，这会将键盘移出视线之外
    func textFieldShouldReturn(textField: UITextField!) -> Bool {
        textField.resignFirstResponder()
        return true
    }// called when 'return' key pressed. return NO to ignore.
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
